<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <script src="https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.js"></script>
  <!-- 导入表格需要的包 -->

  <script src="https://cdn.staticfile.org/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
  <script src="https://cdn.staticfile.org/xlsx/0.18.2/xlsx.full.min.js"></script>

  <script src="../../cdn/vue/vue.global.min.js"></script>
  <link rel="stylesheet" href="../../cdn/element-plus/index.css" />
  <script src="../../cdn/element-plus/index.full.min.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <avue-crud ref="crud" :data="data" :option="option">
      <template #menu-left="{size}">
        <el-button type="primary" :size="size" @click="handleSwitch" icon="el-icon-sort">切 换</el-button>
      </template>
    </avue-crud>
  </div>
</body>
<script>
  var app = Vue.createApp({
    data() {
      return {
        type: true,
        data: [
          {
            name: '张三',
            sex: '男',
            username: 'smallwei',
            password: 'smallwei'
          }, {
            name: '李四',
            sex: '女',
            username: 'avue',
            password: 'avue'
          }
        ],
        option: {},
        option1: {
          addBtn: false,
          column: [
            {
              label: '姓名',
              prop: 'name'
            }, {
              label: '性别',
              prop: 'sex'
            }
          ]
        },
        option2: {
          addBtn: false,
          column: [
            {
              label: '用户名',
              prop: 'username'
            }, {
              label: '密码',
              prop: 'password',
              type: 'password'
            }, {
              label: '姓名',
              prop: 'name'
            }
          ]
        },
      };
    },
    created() {
      this.handleSwitch();
    },
    methods: {
      handleSwitch() {
        this.type = !this.type;
        if (this.type) {
          this.option = this.option1;
        } else {
          this.option = this.option2;
        }
      }
    }
  })
  app.use(ElementPlus)
  app.use(AVUE)
  app.mount('#app')
</script>

</html>